package com.hope.study.rest.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import com.hope.study.rest.vo.StudentVo;

/**
 * 
 * 
 * @author lipenghui@denong.com 2013年8月12日 下午3:32:04
 */
@Path("/students")
public class RestDemo {

    private static int index = 1;
    private static Map<Integer, StudentVo> studentList = new HashMap<Integer, StudentVo>();

    @SuppressWarnings("static-access")
    public RestDemo() {
        if (studentList.size() == 0) {
            this.studentList.put(index, new StudentVo(index++, "hope", "it"));
            this.studentList.put(index, new StudentVo(index++, "this", "finance"));
        }
        
    }

    @GET
    @Path("list")
    @Produces({MediaType.APPLICATION_JSON})
    public List<StudentVo> getAllStudents() {
        List<StudentVo> students = new ArrayList<StudentVo>();
        students.addAll(studentList.values());
//        logger.info("RestDemo.getAllStudents()  get all student"); 
        //com.sun.jersey.api.json.POJOMappingFeature
        
        return students;
    }
    
    
    @GET
    @Path("list1")
    @Produces({MediaType.APPLICATION_XML})
    public List<StudentVo> getAllStudents1() {
        List<StudentVo> students = new ArrayList<StudentVo>();
        students.addAll(studentList.values());
//        logger.info("RestDemo.getAllStudents()  get all student"); 
        //com.sun.jersey.api.json.POJOMappingFeature
        
        return students;
    }
}
